//
//  KanViewController.m
//  Kaoshi
//
//  Created by mayunyong on 15/8/14.
//  Copyright (c) 2015年 mohekeji. All rights reserved.
//

#import "KanViewController.h"
#import "AiTableViewCell.h"
@interface KanViewController ()

@end

//宏
#define  USER_ID 24
@implementation KanViewController
//viewcontroller的生命周期
// 第一个页面将要消失了
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
}
// 第二个页面将要出现
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
}
// 第一个页面已经消失
-(void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
}
    // 第二个页面 已经出现
- (void)viewDidAppear:(BOOL)animated{
        [super viewDidAppear:animated];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    _data = @[
              @{
                  @"headerTitle": @"开头",
                  @"footerTitle": @"尾巴",
                  @"list": @[
                          @{
                              @"title": @"cellone的第一行",
                              @"content": @"cellone的第二行"
                              },
                          @{
                              @"title": @"cellone的第一行",
                              @"content": @"cellone的第二行"
                              }
                          ]
                  },
              @{
                  @"headerTitle": @"开头",
                  @"footerTitle": @"尾巴",
                  @"list": @[
                          @{
                              @"title": @"第二个cellTwo的第一行",
                              @"content": @"第二个cellone的第二行"
                              },
                          @{
                              @"title": @"第二个cellTwo的 第一行",
                              @"content": @"第二个cellone的第二行"
                              }
                          ]
                  }
              ];
    //考试第四题——UserDefault运用
    [[NSUserDefaults standardUserDefaults] setObject:@"马云永" forKey:@"name1"];
    NSString *name=  [[NSUserDefaults standardUserDefaults] valueForKey:@"name1"];
    NSLog(@"%@\n",name);
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"named"];
    NSString *name1=  [[NSUserDefaults standardUserDefaults] valueForKey:@"named"];
    NSLog(@"%@\n",name1);
    //三目运算符
    
    int i = 2, j = 1;
    
    NSString *qq = j>i?@"正":@"负";
    
    //    int k = [qq isEqualToString:@"负"];
    NSLog(@"%@",qq);
    // Do any additional setup after loading the view from its nib.
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}
//第二题UIAlertView
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UIAlertView *cc =[[UIAlertView alloc]initWithTitle:@"提醒" message:@"确认付钱" delegate:self cancelButtonTitle:@"确认" otherButtonTitles:@"肯定", nil];
    [cc show];
}
//cell的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 79;
}




- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *headerView = [[UIView alloc] init];
    headerView.frame = CGRectMake(0, 0, 320, 59);
    headerView.backgroundColor = [UIColor grayColor];
    // add label
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 200, 21)];
    NSDictionary *dic = [_data objectAtIndex:section];
    label.text = dic[@"headerTitle"];
    
    [headerView addSubview:label];
    return headerView;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 89;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *footerview = [[UIView alloc] init];
    footerview.frame = CGRectMake(0, 0, 320, 59);
    footerview.backgroundColor = [UIColor grayColor];
    // add label
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 200, 21)];
    NSDictionary *dic = [_data objectAtIndex:section];
    label.text = dic[@"footertitle"];
    [footerview addSubview:label];
    return footerview;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return _data.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 89;
}

//全局断点已经打开
//cell 的手写绘制
//- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
//{
//    return nil;
//}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSString* string = @"AiTableViewCell";
    AiTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:string];
    if (cell == nil) {
        cell = [[[NSBundle mainBundle]loadNibNamed:string owner:self options:nil] lastObject];
    }
    NSDictionary * dic = [_data objectAtIndex:indexPath.section];
    NSArray * arr = dic [@"list"];
    NSDictionary *dic1 = [arr objectAtIndex:indexPath.row];
    cell.login1.text = dic1[@"title"];
    cell.login2.text = dic1[@"content"];
    return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    NSDictionary *dicThree = [_data objectAtIndex:section];
    NSArray *arrOne = dicThree[@"list"];
    return arrOne.count;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
